<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Show all Users</title>
    <link rel="stylesheet" type="text/css" href="ext-4.2.1.883/resources/css/ext-all.css">
    <script type="text/javascript" src="ext-4.2.1.883/ext-all.js"></script>
    <script type="text/javascript" src="ext-4.2.1.883/locale/ext-lang-zh_CN.js"></script>
</head>
<body>

<script type="text/javascript">
    Ext.onReady(function () {
        Ext.create('Ext.form.Panel',{
            title:'添加用户',
            bodyPadding:5,
            width:350,

            //Ajax请求URL
            url:'http://localhost:8080/user/addUser.do',

            layout:'anchor',
            defaults:{
                anchor:'100%'
            },

            defaultType:'textfield',
            //表格区域
            items:[{
                fieldLabel:'username',
                name:'username',
                allowBlank:false
            },{
                fieldLabel:'password',
                name:'password',
                allowBlank:false
            },{
                fieldLabel:'email',
                name:'email',
                allowBlank:false
            }],
            //添加按钮
            buttons:[{
                text:'添加',
                formBind:true,
                disabled:true,
                handler: function () {
                    var form = this.up('form').getForm();
                    if (form.isValid()){
                        form.submit({
                            success: function (form,action) {
                                //Ext.msg.alert(String title,String context)第一个是标题,第二个是内容
                                Ext.Msg.alert('添加成功',action.result.msg);
                            },
                            failure:function (form,action) {
                                Ext.Msg.alert('添加失败',action.result.msg);
                            }
                        });
                    };
                    this.up('form').getForm();
                }
            }, {
                text: '重置',
                handler: function () {
                    this.up('form').getForm().reset();
                }
            }],
           renderTo:Ext.getBody()
        });
    });

    var addAjax = Ext.create('Ext.Ajax.request',{
        url:'http://localhost:8080/user/addUser.do',
        method:'POST'
//        anysc:false
    })
</script>
</body>
</html>